package com.nondo.dean.order.service;

import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.nondo.dean.common.web.View;
import com.nondo.dean.order.common.OrderTip;
import com.nondo.dean.order.model.OrderDetailBean;

/**
 * 店铺管理业务类
 * 
 * @author zhaoljin
 * @date 2018年4月26日
 */
@Component
public class StoreService {

    @Autowired
    RestTemplate restTemplate;

    /**
     * 将采购产品写入店铺产品
     * @param storeId
     * @param orderDetailList
     */
    public void saveStoreProduct(Integer storeId, List<OrderDetailBean> orderDetailList) {
        HttpEntity<List<OrderDetailBean>> httpEntity = new HttpEntity<List<OrderDetailBean>>(orderDetailList);
        @SuppressWarnings("unchecked")
        View<LinkedHashMap<String, Object>> result =
            restTemplate.postForEntity("http://dean-dealer/dealer/v1/inner/store/" + storeId + "/product/save",
                httpEntity, View.class).getBody();
        if (result.getCode() != 20000 || result.getData() == null) {
            throw new RuntimeException(OrderTip.UPDATE_STORE_PRODUCT_FAIL);
        }
    }

}
